package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Order;
import com.cskaoyan.bean.order.bo.OrderListBo;
import com.cskaoyan.bean.order.bo.OrderRefundBo;
import com.cskaoyan.bean.order.bo.OrderShipBo;
import com.cskaoyan.bean.order.vo.OrderDetailVo;
import com.cskaoyan.bean.order.vo.OrderListVo;
import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangdezhao
 * @date 2021/6/5
 * @description
 */
@RestController
@RequestMapping("admin/order")
public class AdminOrderController {
    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    public BaseRespVo list(OrderListBo listBo) {
        OrderListVo orderListVos = orderService.getOrderList(listBo);
        return BaseRespVo.ok(orderListVos);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        OrderDetailVo orderDetailVo = orderService.getOrderDetail(id);
        return BaseRespVo.ok(orderDetailVo);
    }

    /**
     * 退款, 更改状态码 假删除订单
     * @param refundBo
     * @return
     */
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody OrderRefundBo refundBo) {
        Integer effectedRows = orderService.refund(refundBo);
        return BaseRespVo.ok("成功退款" + effectedRows + "个订单");
    }

    /**
     * 设置快递公司和快递编号, 更改状态码为 301
     * @param shipBo
     * @return
     */
    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody OrderShipBo shipBo) {
        Integer effectedRows = orderService.AddShip(shipBo);
        return BaseRespVo.ok("成功发货" + effectedRows + "个订单");
    }

}
